using System;
using System.Windows.Forms;
using Microsoft.Practices.CompositeUI.SmartParts;
using Microsoft.Practices.ObjectBuilder;
using Jbe.TestSuite.Infrastructure.Interface;
using Jbe.TestSuite.TestDevice.FunctionGen.Interface.Services;
using Jbe.TestSuite.Infrastructure.Interface.Services;
using Microsoft.Practices.CompositeUI;

namespace Jbe.TestSuite.TestDevice.FunctionGen.ControlView.Views
{
    public partial class ConfigurationEdit : UserControl, IConfigurationEdit
    {
        private ConfigurationView configurationView;

        public IFunctionGenConfig Config
        {
            get { return configurationView.Config; }
            set { configurationView.Config = value; }
        }

        public IButtonControl AcceptButton
        {
            get { return okButton; }
        }

        public IButtonControl CancelButton
        {
            get { return cancelButton; }
        }

        public ConfigurationEdit()
        {
            InitializeComponent();

            configurationView = new ConfigurationView();
            configurationView.Dock = DockStyle.Fill;
            configurationView.ReadOnly = false;
            configurationView.IsValidChanged += new EventHandler(ConfigurationViewIsValidChanged);
            configPanel.Controls.Add(configurationView);
        }

        protected override void OnLoad(EventArgs e)
        {
            presenter.OnViewReady();
            base.OnLoad(e);
        }

        private void OKButtonClick(object sender, EventArgs e)
        {
            presenter.Apply();
            presenter.OnCloseView();
        }

        private void CancelButtonClick(object sender, EventArgs e)
        {
            presenter.OnCloseView();
        }

        private void ConfigurationViewIsValidChanged(object sender, EventArgs e)
        {
            okButton.Enabled = configurationView.IsValid;
        }
    }
}